﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true"
    CodeBehind="CRUDGridViewAutoPagingAndSorting.aspx.cs" Inherits="SampleWeb.CRUDGridViewAutoPagingAndSorting" %>

<%@ Register Assembly="GenericDataSourceControl" Namespace="GenericDataSourceControl"
    TagPrefix="cc1" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <cc1:GenericDataSource ID="GenericDataSource1" runat="server" OnExecuteSelect="GenericDataSource1_ExecuteSelect">
    </cc1:GenericDataSource>
    <h3>
        Full CRUD (Create Retrieve Update Delete) Example with GridView using GenericDataSource.
        The DataSource is setup for AutoSorting and AutoPaging</h3>
        <p>The GenericDataSource may also e used for creating GridView custom paging. Check the source code.</p>
    <asp:Label ID="ErrorMessageLabel" runat="server" ForeColor="Red" Visible="false" BorderStyle="Solid" BorderColor="Red" style="padding: 5 5 5 5;"></asp:Label><br />
    <asp:GridView ID="GridView1" runat="server" DataSourceID="GenericDataSource1" AllowSorting="True"
        DataKeyNames="TaskID" Caption="My Tasks" AutoGenerateColumns="False" PageSize="4"
        AllowPaging="true">
        <Columns>
            <asp:BoundField HeaderText="Task" DataField="Title" SortExpression="Title" />
            <asp:BoundField HeaderText="DueOn (date)" DataField="DueOn" SortExpression="DueOn"
                DataFormatString="{0:d}" />
            <asp:BoundField HeaderText="Description" DataField="Description" SortExpression="Description" />
            <asp:BoundField HeaderText="CreatedOn (date)" DataField="CreatedOn" SortExpression="CreatedOn"
                DataFormatString="{0:d}" />
            <asp:CheckBoxField HeaderText="Completed" DataField="Completed" ReadOnly="true" SortExpression="Completed" />
            <asp:TemplateField HeaderText="Complete">
                <ItemTemplate>
                    <asp:LinkButton ID="CompleteButton" runat="server" Text='<%# (bool)Eval("Completed") ? "ReOpen" : "Complete" %>'
                        CommandName='<%# (bool)Eval("Completed") ? "ReOpen" : "Complete" %>' CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowDeleteButton="true" ShowEditButton="true" />
        </Columns>
        <PagerSettings Mode="NumericFirstLast" />
        <PagerTemplate>
            <cc1:GenericDataSource ID="PagingData" runat="server"
                OnExecuteSelect="PagingData_ExecuteSelect">
            </cc1:GenericDataSource>
            <asp:Repeater ID="PagingRepeater" runat="server" OnItemCommand="PagingRepeater_ItemCommand">
                <HeaderTemplate>
                    <span style="font-weight:bold;">Paging:</span>&nbsp;
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="PageButton" runat="server"
                        Text='<%# (int)Container.DataItem + 1 %>'
                        CommandArgument='<%# (int)Container.DataItem %>'
                        CommandName="Page"
                        Enabled='<%# (int)Container.DataItem != GridView1.PageIndex %>'>
                    </asp:LinkButton>
                </ItemTemplate>
                <FooterTemplate>
                    <span>of</span>&nbsp;<asp:Label ID="TotalPages" runat="server" Text='<%# GridView1.PageCount %>'></asp:Label>&nbsp;<span>pages</span>
                </FooterTemplate>
            </asp:Repeater>
        </PagerTemplate>
    </asp:GridView>
    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Insert" AutoGenerateRows="false"
        DataSourceID="GenericDataSource1" Caption="Add new task">
        <Fields>
            <asp:BoundField HeaderText="Task" DataField="Title" />
            <asp:BoundField HeaderText="Description" DataField="Description" />
            <asp:BoundField HeaderText="DueOn (date)" DataField="DueOn" />
            <asp:CommandField ShowInsertButton="true" />
        </Fields>
    </asp:DetailsView>
</asp:Content>
